package curl2

import (
	"fmt"
	"net/http"
	"time"

	"github.com/christophwitzko/go-curl"
)

func Christop_curl() {
	//var st curl.IoCopyStat
	//curl.File("http://192.168.0.168:8888/hawkeye/hawkeye-pagent-1.2.3.tar.gz", "a.tar.gz", &st)
	//curl.Bytes("http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M1/bin/apache-tomcat-9.0.0.M1.tar.gz",&st)
	con := &curl.Control{}
	header := http.Header{
		"User-Agent": {"curl/7.29.0"},
		//"Host":       {"www.ts.cloud.com"},
	}
	//http://192.168.0.168:8888/hawkeye/hawkeye-pagent-1.2.3.tar.gz
	//var dur time.Duration //下载时间
	//curl.String("http://192.168.0.168:8888/hawkeye/hawkeye-pagent-1.2.3.tar.gz", &st, "header=", header, "deadline=", time.Second*10)
	curl.String("http://192.168.0.168:8888/hawkeye/hawkeye-pagent-1.2.3.tar.gz", con, "method=", "HEAD", "header=", header, "deadline=", time.Second*10)
	st := con.Stat()
	fmt.Println("开始时间", st.Begin)
	fmt.Println("下载时间", st.Dur)
	fmt.Println("下载速度", curl.PrettySpeed(st.Speed))
	fmt.Println("下载大小", curl.PrettySize(st.Size))
	fmt.Println("文件大小", curl.PrettySize(st.Length))
	fmt.Println("状态码", st.Response.StatusCode)
	fmt.Println("Response", st.Response.Header)

	for k, v := range st.Header {
		fmt.Println(k, v)
	}
}
